let v = new Vue({
    el:'#main-container',
    data:{
        pageInfo:{
            pageSize:5,
        },
        user:{
            realName:''
        },
        loginUser:{

        }
    },
    methods:{
        selectByName:function (page,pageSize) {
            axios({
                url:`main/user/selectByPage/${page}/${pageSize}`,
                method:'post',
                data:this.user,
            }).then(resp => {
                this.pageInfo = resp.data.obj.pageInfo;
                this.loginUser = resp.data.obj.loginUser;
                for (let i = 0; i < this.loginUser.focusUsers.length; i++) {
                    for (let j = 0; j < this.pageInfo.list.length; j++) {
                        if(this.loginUser.focusUsers[i]==this.pageInfo.list[j].id){
                            this.pageInfo.list[j].focus = true;
                        }
                    }
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        selectByPage:function (page,pageSize) {
            this.name = '';
            this.selectByName(1,pageSize);
        },
        toDetail:function (thisUser) {
            layer.obj = thisUser;
            if(thisUser.isSecret == 0){
                layer.msg("该用户设置了私密信息，不可查看");
            }else{
                layer.open({
                    type: 2,
                    title: '详细信息',
                    area: ['80%', '80%'],
                    content: 'main/user/toDetail',
                    end:() => {

                    }
                })
            }

        },
        changeFocus:function (user) {
            if(user.focus){
                //取消关注
                console.log('取消关注');
                axios({
                    url:'main/user/unfocus',
                    method:'post',
                    data:user,
                }).then(resp => {
                    layer.msg(resp.data.msg);
                    // user.
                    if(!resp.data.success){
                        this.selectByName(this.pageInfo.pageNum,this.pageInfo.pageSize);
                    }
                }).catch(error => {
                    layer.msg(error.message);
                })
            }else {
                console.log('关注');
                axios({
                    url:'main/user/focus',
                    method:'post',
                    data:user,
                }).then(resp => {
                    layer.msg(resp.data.msg);
                    if(!resp.data.success){
                        this.selectByName(this.pageInfo.pageNum,this.pageInfo.pageSize);
                    }
                }).catch(error => {
                    layer.msg(error.message);
                })
            }
        }
    },
    created:function () {
        this.selectByPage(1,this.pageInfo.pageSize);
    }
})